package com.iss.examsys.entity;

import java.io.Serializable;
import java.math.BigInteger;
import java.util.Collection;
import java.util.Date;
import java.util.List;
import javax.persistence.Basic;
import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.NamedQueries;
import javax.persistence.NamedQuery;
import javax.persistence.OneToMany;
import javax.persistence.Table;
import javax.persistence.Temporal;
import javax.persistence.TemporalType;
import javax.persistence.Version;
import javax.validation.constraints.NotNull;
import javax.validation.constraints.Size;
import javax.xml.bind.annotation.XmlRootElement;
import javax.xml.bind.annotation.XmlTransient;

@Entity
@Table(name = "module")
@XmlRootElement
@NamedQueries({
    @NamedQuery(name = "Module.findAll", query = "SELECT m FROM Module m"),
    @NamedQuery(name = "Module.findById", query = "SELECT m FROM Module m WHERE m.id = :id"),
    @NamedQuery(name = "Module.findByCode", query = "SELECT m FROM Module m WHERE m.code = :code"),
    @NamedQuery(name = "Module.findByCodeFilterId", query = "SELECT m FROM Module m WHERE m.code = :code and m.id != :id"),
    @NamedQuery(name = "Module.findByName", query = "SELECT m FROM Module m WHERE m.name = :name"),
    @NamedQuery(name = "Module.findByLectureId", query = "SELECT m FROM Module m, LecturerModule lm WHERE m.id = lm.moduleId.id and lm.lecturerId.id = :lectureid")})
public class Module implements Serializable {
    @OneToMany(cascade = CascadeType.ALL, mappedBy = "moduleId")
    private List<LecturerModule> lecturerModuleList;
    @OneToMany(cascade = CascadeType.ALL, mappedBy = "moduleId")
    private List<ExamPaper> examPaperList;
    @OneToMany(cascade = CascadeType.ALL, mappedBy = "moduleId")
    private List<StudentModule> studentModuleList;
    
    private static final long serialVersionUID = 1L;
    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    @Basic(optional = false)
    @Column(name = "ID")
    private Long id;
    @Basic(optional = false)
    @NotNull
    @Size(min = 1, max = 50)
    @Column(name = "CODE")
    private String code;
    @Size(max = 50)
    @Column(name = "NAME")
    private String name;
    @Version
    private Integer version;
    @Column(name = "CREATED_DATE")
    @Temporal(TemporalType.TIMESTAMP)
    private Date createdDate;
    @Column(name = "CREATED_BY")
    private BigInteger createdBy;
    @Column(name = "MODIFIED_DATE")
    @Temporal(TemporalType.TIMESTAMP)
    private Date modifiedDate;
    @Column(name = "MODIFIED_BY")
    private BigInteger modifiedBy;

    @OneToMany(cascade = CascadeType.ALL, mappedBy = "moduleId")
    private List<Question> questionList;
    
    public Module() {
    }

    public Module(Long id) {
        this.id = id;
    }

    public Module(Long id, String code) {
        this.id = id;
        this.code = code;
    }

    public Long getId() {
        return id;
    }

    public void setId(Long id) {
        this.id = id;
    }

    public String getCode() {
        return code;
    }

    public void setCode(String code) {
        this.code = code;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public Integer getVersion() {
        return version;
    }

    public void setVersion(Integer version) {
        this.version = version;
    }

    public Date getCreatedDate() {
        return createdDate;
    }

    public void setCreatedDate(Date createdDate) {
        this.createdDate = createdDate;
    }

    public BigInteger getCreatedBy() {
        return createdBy;
    }

    public void setCreatedBy(BigInteger createdBy) {
        this.createdBy = createdBy;
    }

    public Date getModifiedDate() {
        return modifiedDate;
    }

    public void setModifiedDate(Date modifiedDate) {
        this.modifiedDate = modifiedDate;
    }

    public BigInteger getModifiedBy() {
        return modifiedBy;
    }

    public void setModifiedBy(BigInteger modifiedBy) {
        this.modifiedBy = modifiedBy;
    }

    @Override
    public int hashCode() {
        int hash = 0;
        hash += (id != null ? id.hashCode() : 0);
        return hash;
    }

    @Override
    public boolean equals(Object object) {
        // TODO: Warning - this method won't work in the case the id fields are not set
        if (!(object instanceof Module)) {
            return false;
        }
        Module other = (Module) object;
        if ((this.id == null && other.id != null) || (this.id != null && !this.id.equals(other.id))) {
            return false;
        }
        return true;
    }

    @Override
    public String toString() {
        return name;
    }

    @XmlTransient
    public List<Question> getQuestionList() {
        return questionList;
    }

    public void setQuestionList(List<Question> questionList) {
        this.questionList = questionList;
    }

    @XmlTransient
    public List<LecturerModule> getLecturerModuleList() {
        return lecturerModuleList;
    }

    public void setLecturerModuleList(List<LecturerModule> lecturerModuleList) {
        this.lecturerModuleList = lecturerModuleList;
    }

    @XmlTransient
    public List<ExamPaper> getExamPaperList() {
        return examPaperList;
    }

    public void setExamPaperList(List<ExamPaper> examPaperList) {
        this.examPaperList = examPaperList;
    }

    @XmlTransient
    public List<StudentModule> getStudentModuleList() {
        return studentModuleList;
    }

    public void setStudentModuleList(List<StudentModule> studentModuleList) {
        this.studentModuleList = studentModuleList;
    }
    
}
